package com.plume.code.core.common.model;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ConnectionModel {
    private String type;
    private String driver;
    private String url;
    private String username;
    private String password;
    private String schema;
	public String getSchema() {
		String regex = "currentSchema=([^&]*)";
	    Pattern pattern = Pattern.compile(regex);
	    Matcher matcher = pattern.matcher(getUrl());
	
	    if (matcher.find()) {
	        String currentSchema = matcher.group(1);
	        return currentSchema;
	    } else {
	    	schema = getUsername().toUpperCase();
	    }
		return schema;
	}
}
